package com.qianyu.project.web.controller.sy;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qianyu.project.entity.IncomeContract;
import com.qianyu.project.service.IIncomeContractService;
import com.qianyu.project.utils.PageUtil;
import com.qianyu.project.utils.Result;
import com.qianyu.project.utils.ResultTool;
import com.qianyu.project.vo.IncomeContractExtend;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


@RestController
@RequestMapping("incomeContract")
public class IncomeContractController {

    @Autowired
    private IIncomeContractService incomeContractService;

    @GetMapping("getMaxId")
    public Result getMaxId(){
        return ResultTool.success(Long.parseLong(incomeContractService.getMaxId()) + 1);
    }

    /**
     * 添加收入合同的方法
     * @param incomeContractExtend
     * @return
     */
    @PostMapping
    public Result save(@RequestBody IncomeContractExtend incomeContractExtend){
        incomeContractService.saveDetails(incomeContractExtend.getIncomeForm(), incomeContractExtend.getIncomeDetails());
        return ResultTool.success();
    }

    /**
     * 查询收入合同列表的数据
     * @param params
     * @return
     */
    @GetMapping
    public Result getIncomeContractData(@RequestParam Map<String, String> params){
        return ResultTool.success(incomeContractService.getPageData(params));
    }

    /**
     * 用id查询单个数据
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public Result selectOne(@PathVariable String id){
        return ResultTool.success(incomeContractService.selectOne(id));
    }

    /**
     * 用id查询单个数据
     * @param id
     * @return
     */
    @GetMapping("{id}/byPid")
    public Result selectByPid(@PathVariable String id){
        return ResultTool.success(incomeContractService.selectByPid(id));
    }

    /**
     * 查询收入合同明细
     * @param params
     * @return
     */
    @GetMapping("info")
    public Result selectInfo(@RequestParam Map<String, String> params){
        return ResultTool.success(incomeContractService.selectInfo(params));
    }

    /**
     * 查询收入合同报表
     *
     * @param params
     * @return
     */
    @GetMapping("report")
    public Result selectReport(@RequestParam Map<String, String> params) {
        return ResultTool.success(incomeContractService.selectReport(params));
    }

}
